<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha256-xejo6yLi6vGtAjcMIsY8BHdKsLg7QynVlFMzdQgUuy8=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" integrity="sha256-Vzbj7sDDS/woiFS3uNKo8eIuni59rjyNGtXfstRzStA=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"gz1234.gitee.io","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.12.3","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"flat"},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="React规范文件组织 [强制]同一目录下不得拥有同名的.js和.jsx文件。   在使用模块导入时，倾向于不添加后缀，如果存在同名但不同后缀的文件，构建工具将无法决定哪一个是需要引入的模块。  [强制]组件文件使用一致的.js或 .jsx后缀。   所有组件文件的后缀名从.js或.jsx中任选其一。   不应在项目中出现部分组件为.js文件，部分为.jsx的情况。  [强制]每一个文件以expo">
<meta property="og:type" content="website">
<meta property="og:title" content="郭泽">
<meta property="og:url" content="https://gz1234.gitee.io/spec-master/react-style-guide.html">
<meta property="og:site_name" content="郭泽">
<meta property="og:description" content="React规范文件组织 [强制]同一目录下不得拥有同名的.js和.jsx文件。   在使用模块导入时，倾向于不添加后缀，如果存在同名但不同后缀的文件，构建工具将无法决定哪一个是需要引入的模块。  [强制]组件文件使用一致的.js或 .jsx后缀。   所有组件文件的后缀名从.js或.jsx中任选其一。   不应在项目中出现部分组件为.js文件，部分为.jsx的情况。  [强制]每一个文件以expo">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-05-31T00:57:28.726Z">
<meta property="article:modified_time" content="2023-05-31T00:57:28.726Z">
<meta property="article:author" content="郭泽">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://gz1234.gitee.io/spec-master/react-style-guide">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":false,"lang":"zh-CN","comments":true,"permalink":"https://gz1234.gitee.io/spec-master/react-style-guide.html","path":"spec-master/react-style-guide.html","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title> | 郭泽
</title>
  





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">郭泽</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#React%E8%A7%84%E8%8C%83"><span class="nav-number">1.</span> <span class="nav-text">React规范</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E7%BB%84%E7%BB%87"><span class="nav-number">1.1.</span> <span class="nav-text">文件组织</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99"><span class="nav-number">1.2.</span> <span class="nav-text">命名规则</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%84%E4%BB%B6%E5%A3%B0%E6%98%8E"><span class="nav-number">1.3.</span> <span class="nav-text">组件声明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%84%E4%BB%B6%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.4.</span> <span class="nav-text">组件实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSX"><span class="nav-number">1.5.</span> <span class="nav-text">JSX</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">郭泽</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">54</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">51</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner page posts-expand">


    
    
    
    <div class="post-block" lang="zh-CN"><header class="post-header">

<h1 class="post-title" itemprop="name headline">
</h1>

<div class="post-meta-container">
</div>

</header>

      
      
      <div class="post-body">
          <h1 id="React规范"><a href="#React规范" class="headerlink" title="React规范"></a>React规范</h1><h2 id="文件组织"><a href="#文件组织" class="headerlink" title="文件组织"></a>文件组织</h2><ul>
<li><p>[强制]同一目录下不得拥有同名的<code>.js</code>和<code>.jsx</code>文件。</p>
<p>  在使用模块导入时，倾向于不添加后缀，如果存在同名但不同后缀的文件，构建工具将无法决定哪一个是需要引入的模块。</p>
</li>
<li><p>[强制]组件文件使用一致的<code>.js</code>或 <code>.jsx</code>后缀。</p>
<p>  所有组件文件的后缀名从<code>.js</code>或<code>.jsx</code>中任选其一。</p>
<p>  不应在项目中出现部分组件为<code>.js</code>文件，部分为<code>.jsx</code>的情况。</p>
</li>
<li><p>[强制]每一个文件以<code>export default</code>的形式暴露一个组件。</p>
<p>  允许一个文件中存在多个不同的组件，但仅允许通过<code>export default</code>暴露一个组件，其它组件均定义为内部组件。</p>
</li>
<li><p>[强制]每个存放组件的目录使用一个<code>index.js</code>以命名导出的形式暴露所有组件。</p>
<p>  同目录内的组件相互引用使用<code>import Foo from &#39;./Foo&#39;;</code>进行。</p>
<p>  引用其它目录的组件使用<code>import &#123;Foo&#125; from &#39;../component&#39;;</code>进行。</p>
<p>  建议使用<a target="_blank" rel="noopener" href="https://marketplace.visualstudio.com/items?itemName=BrunoLM.export-index">VSCode的export-index插件</a>等插件自动生成<code>index.js</code>的内容。</p>
</li>
</ul>
<h2 id="命名规则"><a href="#命名规则" class="headerlink" title="命名规则"></a>命名规则</h2><ul>
<li><p>[强制]组件名为PascalCase。</p>
<p>  包括函数组件，名称均为PascalCase。</p>
</li>
<li><p>[强制]组件名称与文件名称保持相同。</p>
<p>  同时组件名称应当能体现出组件的功能，以便通过观察文件名即确定使用哪一个组件。</p>
</li>
<li><p>[强制]高阶组件使用camelCase命名。</p>
<p>  高阶组件事实上并非一个组件，而是一个“生成组件类型”的函数，因此遵守JavaScript函数命名的规范，使用camelCase命名。</p>
</li>
<li><p>[强制]使用<code>onXxx</code>形式作为<code>props</code>中用于回调的属性名称。</p>
<p>  使用统一的命名规则用以区分<code>props</code>中回调和非回调部分的属性，在JSX上可以清晰地看到一个组件向上和向下的逻辑交互。</p>
<p>  对于不用于回调的函数类型的属性，使用动词作为属性名称。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// onClick作为回调以on开头，renderText非回调函数则使用动词</span></span><br><span class="line"><span class="keyword">let</span> Label = <span class="function">(<span class="params">&#123;onClick, renderText&#125;</span>) =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span> <span class="attr">onClick</span>=<span class="string">&#123;onClick&#125;</span>&gt;</span>&#123;renderText()&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[建议]使用<code>withXxx</code>或<code>xxxable</code>形式的词作为高阶组件的名称。</p>
<p>  高阶组件是为组件添加行为和功能的函数，因此使用如上形式的词有助于对其功能进行理解。</p>
</li>
<li><p>[建议]作为组件方法的事件处理函数以具备业务含义的词作为名称，不使用<code>onXxx</code>形式命名。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Form</span> </span>&#123;</span><br><span class="line">    @autobind</span><br><span class="line">    <span class="function"><span class="title">collectAndSubmitData</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">let</span> data = &#123;</span><br><span class="line">            name: <span class="built_in">this</span>.state.name,</span><br><span class="line">            age: <span class="built_in">this</span>.state.age</span><br><span class="line">        &#125;;</span><br><span class="line">        <span class="built_in">this</span>.props.onSubmit(data);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @autobind</span><br><span class="line">    <span class="function"><span class="title">syncName</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @autobind</span><br><span class="line">    <span class="function"><span class="title">syncAge</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            &lt;div&gt;</span><br><span class="line">                &lt;label&gt;姓名：&lt;input type=<span class="string">&quot;text&quot;</span> onChange=&#123;<span class="built_in">this</span>.syncName&#125; /&gt;&lt;/label&gt;</span><br><span class="line">                &lt;label&gt;年龄：&lt;input type=<span class="string">&quot;number&quot;</span> onChange=&#123;<span class="built_in">this</span>.syncAge&#125; /&gt;&lt;/label&gt;</span><br><span class="line">                &lt;button type=<span class="string">&quot;button&quot;</span> onClick=&#123;<span class="built_in">this</span>.collectAndSubmit&#125;&gt;提交&lt;/button&gt;</span><br><span class="line">            &lt;/div&gt;</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="组件声明"><a href="#组件声明" class="headerlink" title="组件声明"></a>组件声明</h2><ul>
<li><p>[强制]使用ES Class声明组件，禁止使用<code>React.createClass</code>。</p>
<p>  <a target="_blank" rel="noopener" href="https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html">React v15.5.0</a>已经弃用了<code>React.createClass</code>函数。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line"><span class="keyword">let</span> Message = React.createClass(&#123;</span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;this.state.message&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Message</span> <span class="keyword">extends</span> <span class="title">PureComponent</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;this.state.message&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]不使用<code>state</code>的组件声明为函数组件。</p>
<p>  函数组件在React中有着特殊的地位，在将来也有可能得到更多的内部优化。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">NextNumber</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;this.props.value + 1&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="keyword">let</span> NextNumber = <span class="function">(<span class="params">&#123;value&#125;</span>) =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;value + 1&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]所有组件均需声明<code>propTypes</code>。</p>
<p>  <code>propsTypes</code>在提升组件健壮性的同时，也是一种类似组件的文档的存在，有助于代码的阅读和理解。</p>
</li>
<li><p>[强制]对于所有非<code>isRequired</code>的属性，在<code>defaultProps</code>中声明对应的值。</p>
<p>  声明初始值有助于对组件初始状态的理解，也可以减少<code>propTypes</code>对类型进行校验产生的开销。</p>
<p>  对于初始没有值的属性，应当声明初始值为<code>null</code>而非<code>undefined</code>。</p>
</li>
<li><p>[强制]如无必要，使用静态属性语法声明<code>propsTypes</code>、<code>contextTypes</code>、<code>defaultProps</code>和<code>state</code>。</p>
<p>  仅当初始<code>state</code>需要从<code>props</code>计算得到的时候，才将<code>state</code>的声明放在构造函数中，其它情况下均使用静态属性声明进行。</p>
</li>
<li><p>[强制]依照规定顺序编排组件中的方法和属性。</p>
<p>  按照以下顺序编排组件中的方法和属性：</p>
<ol>
<li><p><code>static displayName</code></p>
</li>
<li><p><code>static propTypes</code></p>
</li>
<li><p><code>static contextTypes</code></p>
</li>
<li><p><code>state defaultProps</code></p>
</li>
<li><p><code>static state</code></p>
</li>
<li><p>其它静态的属性</p>
</li>
<li><p>用于事件处理并且以属性的方式（<code>onClick = e =&gt; &#123;...&#125;</code>）声明的方法</p>
</li>
<li><p>其它实例属性</p>
</li>
<li><p><code>constructor</code></p>
</li>
<li><p><code>getChildContext</code></p>
</li>
<li><p><code>componentWillMount</code></p>
</li>
<li><p><code>componentDidMount</code></p>
</li>
<li><p><code>shouldComponentUpdate</code></p>
</li>
<li><p><code>componentWillUpdate</code></p>
</li>
<li><p><code>componentDidUpdate</code></p>
</li>
<li><p><code>componentWillUnmount</code></p>
</li>
<li><p>事件处理方法</p>
</li>
<li><p>其它方法</p>
</li>
<li><p><code>render</code></p>
<p>其中<code>shouldComponentUpdate</code>和<code>render</code>是一个组件最容易被阅读的函数，因此放在最下方有助于快速定位。</p>
</li>
</ol>
</li>
<li><p>[建议]无需显式引入React对象。</p>
<p>  使用JSX隐式地依赖当前环境下有<code>React</code>这一对象，但在源码上并没有显式使用，这种情况下添加<code>import React from &#39;react&#39;;</code>会造成一个没有使用的变量存在。</p>
<p>  使用<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/babel-plugin-react-require">babel-plugin-react-require</a>插件可以很好地解决这一问题，因此无需显式地编写<code>import React from &#39;react&#39;;</code>这一语句。</p>
</li>
<li><p>[建议]使用箭头函数声明函数组件。</p>
<p>  箭头函数具备更简洁的语法（无需<code>function</code>关键字），且可以在仅有一个语句时省去<code>return</code>造成的额外缩进。</p>
</li>
<li><p>[建议]高阶组件返回新的组件类型时，添加<code>displayName</code>属性。</p>
<p>  同时在<code>displayName</code>上声明高阶组件的存在。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="keyword">let</span> asPureComponent = <span class="function"><span class="params">Component</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">let</span> componentName = Component.displayName || Component.name || <span class="string">&#x27;UnknownComponent&#x27;</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="class"><span class="keyword">class</span> <span class="keyword">extends</span> <span class="title">PureComponent</span> </span>&#123;</span><br><span class="line">        <span class="keyword">static</span> displayName = <span class="string">`asPure(<span class="subst">$&#123;componentName&#125;</span>)`</span></span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">Component</span> &#123;<span class="attr">...this.props</span>&#125; /&gt;</span></span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="组件实现"><a href="#组件实现" class="headerlink" title="组件实现"></a>组件实现</h2><ul>
<li><p>[强制]除顶层或路由级组件以外，所有组件均在概念上实现为纯组件（Pure Component）。</p>
<p>  本条规则并非要求组件继承自<code>PureComponent</code>，“概念上的纯组件”的意思为一个组件在<code>props</code>和<code>state</code>没有变化（shallowEqual）的情况下，渲染的结果应保持一致，即<code>shouldComponentUpdate</code>应当返回<code>false</code>。</p>
<p>  一个典型的非纯组件是使用了随机数或日期等函数：</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> RandomNumber = <span class="function">() =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;Math.random()&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br><span class="line"><span class="keyword">let</span> Clock = <span class="function">() =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;Date.time()&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span>;</span><br></pre></td></tr></table></figure>

<p>  非纯组件具备向上的“传染性”，即一个包含非纯组件的组件也必须是非纯组件，依次沿组件树结构向上。由于非纯组件无法通过<code>shouldComponentUpdate</code>优化渲染性能且具备传染性，因此要避免在非顶层或路由组件中使用。</p>
<p>  如果需要在组件树的某个节点使用随机数、日期等非纯的数据，应当由顶层组件生成这个值并通过<code>props</code>传递下来。对于使用Redux等应用状态管理的系统，可以在应用状态中存放相关值（如Redux使用Action Creator生成这些值并通过Action和reducer更新到store中）。</p>
</li>
<li><p>[强制]禁止为继承自<code>PureComponent</code>的组件编写<code>shouldComponentUpdate</code>实现。</p>
<p>  参考<a target="_blank" rel="noopener" href="https://github.com/facebook/react/issues/9239">React的相关Issue</a>，在React的实现中，<code>PureComponent</code>并不直接实现<code>shouldComponentUpdate</code>，而是添加一个<code>isReactPureComponent</code>的标记，由<code>CompositeComponent</code>通过识别这个标记实现相关的逻辑。因此在<code>PureComponent</code>上自定义<code>shouldComponentUpdate</code>并无法享受<code>super.shouldComponentUpdate</code>的逻辑复用，也会使得这个继承关系失去意义。</p>
</li>
<li><p>[强制]为非继承自<code>PureComponent</code>的纯组件实现<code>shouldComponentUpdate</code>方法。</p>
<p>  <code>shouldComponentUpdate</code>方法在React的性能中扮演着至关重要的角色，纯组件必定能通过<code>props</code>和<code>state</code>的变化来决定是否进行渲染，因此如果组件为纯组件且不继承<code>shouldComponentUpdate</code>，则应当有自己的<code>shouldComponentUpdate</code>实现来减少不必要的渲染。</p>
</li>
<li><p>[建议]为函数组件添加<code>PureComponent</code>能力。</p>
<p>  函数组件并非一定是纯组件，因此其<code>shouldComponentUpdate</code>的实现为<code>return true;</code>，这可能导致额外的无意义渲染，因此推荐使用高阶组件为其添加<code>shouldComponentUpdate</code>的相关逻辑。</p>
<p>  推荐使用<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/react-pure-stateless-component">react-pure-stateless-component</a>库实现这一功能。</p>
</li>
<li><p>[建议]使用<code>@autobind</code>进行事件处理方法与<code>this</code>的绑定。</p>
<p>  由于<code>PureComponent</code>使用<a target="_blank" rel="noopener" href="https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js"><code>shallowEqual</code></a>进行是否渲染的判断，如果在JSX中使用<code>bind</code>或箭头函数绑定<code>this</code>会造成子组件每次获取的函数都是一个新的引用，这破坏了<code>shouldComponentUpdate</code>的逻辑，引入了无意义的重复渲染，因此需要在<code>render</code>调用之前就将事件处理方法与<code>this</code>绑定，在每次<code>render</code>调用中获取同样的引用。</p>
<p>  当前比较流行的事前绑定<code>this</code>的方法有2种，其一使用类属性的语法：</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span> </span>&#123;</span><br><span class="line">    onClick = <span class="function"><span class="params">e</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>  其二使用<code>@autobind</code>的装饰器：</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span> </span>&#123;</span><br><span class="line">    @autobind</span><br><span class="line">    <span class="function"><span class="title">onClick</span>(<span class="params">e</span>)</span> &#123;</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>  使用类属性语法虽然可以避免引入一个<code>autobind</code>的实现，但存在一定的缺陷：</p>
<ol>
<li><p>对于新手不容易理解函数内的<code>this</code>的定义。</p>
</li>
<li><p>无法在函数上使用其它的装饰器（如<code>memoize</code>、<code>deprecated</code>或检验相关的逻辑等）。</p>
<p>因此，推荐使用<code>@autobind</code>装饰器实现<code>this</code>的事先绑定，推荐使用<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/core-decorators">core-decorators</a>库提供的相关装饰器实现。</p>
</li>
</ol>
</li>
</ul>
<h2 id="JSX"><a href="#JSX" class="headerlink" title="JSX"></a>JSX</h2><ul>
<li><p>[强制]没有子节点的非DOM组件使用自闭合语法。</p>
<p>  对于DOM节点，按照HTML编码规范相关规则进行闭合，<strong>其中void element使用自闭合语法</strong>。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line">&lt;Foo&gt;&lt;/Foo&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line">&lt;Foo /&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]保持起始和结束标签在同一层缩进。</p>
<p>  对于标签前面有其它语句（如<code>return</code>的情况，使用括号进行换行和缩进）。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Message</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> &lt;div&gt;</span><br><span class="line">            &lt;span&gt;Hello World&lt;/span&gt;</span><br><span class="line">        &lt;/div&gt;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Message</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            &lt;div&gt;</span><br><span class="line">                &lt;span&gt;Hello World&lt;/span&gt;</span><br><span class="line">            &lt;/div&gt;</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>  对于直接<code>return</code>的函数组件，可以直接使用括号而省去大括号和<code>return</code>关键字：</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> Message = <span class="function">() =&gt;</span> (</span><br><span class="line">    &lt;div&gt;</span><br><span class="line">        &lt;span&gt;Hello World&lt;/span&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]对于多属性需要换行，从第一个属性开始，每个属性一行。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 没有子节点</span></span><br><span class="line">&lt;SomeComponent</span><br><span class="line">    longProp=&#123;longProp&#125;</span><br><span class="line">    anotherLongProp=&#123;anotherLongProp&#125;</span><br><span class="line">/&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 有子节点</span></span><br><span class="line">&lt;SomeComponent</span><br><span class="line">    longProp=&#123;longProp&#125;</span><br><span class="line">    anotherLongProp=&#123;anotherLongProp&#125;</span><br><span class="line">&gt;</span><br><span class="line">    &lt;SomeChild /&gt;</span><br><span class="line">    &lt;SomeChild /&gt;</span><br><span class="line">&lt;/SomeComponent&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]以字符串字面量作为值的属性使用双引号（<code>&quot;</code>），在其它类型表达式中的字符串使用单引号（<code>&#39;</code>）。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line">&lt;Foo bar=<span class="string">&#x27;bar&#x27;</span> /&gt;</span><br><span class="line">&lt;Foo style=&#123;&#123;<span class="attr">width</span>: <span class="string">&quot;20px&quot;</span>&#125;&#125; /&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line">&lt;Foo bar=<span class="string">&quot;bar&quot;</span> /&gt;</span><br><span class="line">&lt;Foo style=&#123;&#123;<span class="attr">width</span>: <span class="string">&#x27;20px&#x27;</span>&#125;&#125; /&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]自闭合标签的<code>/&gt;</code>前添加一个空格。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line">&lt;Foo bar=<span class="string">&quot;bar&quot;</span>/&gt;</span><br><span class="line">&lt;Foo bar=<span class="string">&quot;bar&quot;</span>  /&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line">&lt;Foo bar=<span class="string">&quot;bar&quot;</span> /&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]对于值为<code>true</code>的属性，省去值部分。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line">&lt;Foo visible=&#123;<span class="literal">true</span>&#125; /&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line">&lt;Foo visible /&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[强制]对于需要使用<code>key</code>的场合，提供一个唯一标识作为<code>key</code>属性的值，禁止使用可能会变化的属性（如索引）。</p>
<p>  <code>key</code>属性是React在进行列表更新时的重要属性，如该属性会发生变化，渲染的性能和<strong>正确性</strong>都无法得到保证。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line">&#123;list.map(<span class="function">(<span class="params">item, index</span>) =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">Foo</span> <span class="attr">key</span>=<span class="string">&#123;index&#125;</span> &#123;<span class="attr">...item</span>&#125; /&gt;</span></span>)&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line">&#123;list.map(<span class="function"><span class="params">item</span> =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">Foo</span> <span class="attr">key</span>=<span class="string">&#123;item.id&#125;</span> &#123;<span class="attr">...item</span>&#125; /&gt;</span></span>)&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>[建议]避免在JSX的属性值中直接使用对象和函数表达式。</p>
<p>  <code>PureComponent</code>使用<a target="_blank" rel="noopener" href="https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js"><code>shallowEqual</code></a>对<code>props</code>和<code>state</code>进行比较来决定是否需要渲染，而在JSX的属性值中使用对象、函数表达式会造成每一次的对象引用不同，从而<code>shallowEqual</code>会返回<code>false</code>，导致不必要的渲染。</p>
</li>
</ul>
<pre><code><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">WarnButton</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="title">alertMessage</span>(<span class="params">message</span>)</span> &#123;</span><br><span class="line">        alert(message);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">onClick</span>=<span class="string">&#123;()</span> =&gt;</span> this.alertMessage(this.props.message)&#125;&gt;提示<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">WarnButton</span> </span>&#123;</span><br><span class="line">    @autobind</span><br><span class="line">    <span class="function"><span class="title">alertMessage</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        alert(<span class="built_in">this</span>.props.message);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">onClick</span>=<span class="string">&#123;this.alertMessage&#125;</span>&gt;</span>提示<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></code></pre>
<ul>
<li><p>[建议]将JSX的层级控制在3层以内。</p>
<p>  JSX提供了基于组件的便携的复用形式，因此可以通过将结构中的一部分封装为一个函数组件来很好地拆分大型复杂的结构。层次过深的结构会带来过多缩进、可读性下降等缺点。如同控制函数内代码行数和分支层级一样，对JSX的层级进行控制可以有效提升代码的可维护性。</p>
  <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Bad</span></span><br><span class="line"><span class="keyword">let</span> List = <span class="function">(<span class="params">&#123;items&#125;</span>) =&gt;</span> (</span><br><span class="line">    &lt;ul&gt;</span><br><span class="line">        &#123;</span><br><span class="line">            items.map(<span class="function"><span class="params">item</span> =&gt;</span> (</span><br><span class="line">                &lt;li&gt;</span><br><span class="line">                    &lt;header&gt;</span><br><span class="line">                        &lt;h3&gt;&#123;item.title&#125;&lt;/h3&gt;</span><br><span class="line">                        &lt;span&gt;&#123;item.subtitle&#125;&lt;/span&gt;</span><br><span class="line">                    &lt;/header&gt;</span><br><span class="line">                    &lt;section&gt;&#123;item.content&#125;&lt;/section&gt;</span><br><span class="line">                    &lt;footer&gt;</span><br><span class="line">                        &lt;span&gt;&#123;item.author&#125;&lt;<span class="regexp">/span&gt;@&lt;time&gt;&#123;item.postTime&#125;&lt;/</span>time&gt;</span><br><span class="line">                    &lt;/footer&gt;</span><br><span class="line">                &lt;/li&gt;</span><br><span class="line">            ))</span><br><span class="line">        &#125;</span><br><span class="line">    &lt;/ul&gt;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Good</span></span><br><span class="line"><span class="keyword">let</span> Header = <span class="function">(<span class="params">&#123;title, subtitle&#125;</span>) =&gt;</span> (</span><br><span class="line">    &lt;header&gt;</span><br><span class="line">        &lt;h3&gt;&#123;title&#125;&lt;/h3&gt;</span><br><span class="line">        &lt;span&gt;&#123;subtitle&#125;&lt;/span&gt;</span><br><span class="line">    &lt;/header&gt;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> Content = <span class="function">(<span class="params">&#123;content&#125;</span>) =&gt;</span> <span class="xml"><span class="tag">&lt;<span class="name">section</span>&gt;</span>&#123;content&#125;<span class="tag">&lt;/<span class="name">section</span>&gt;</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> Footer = <span class="function">(<span class="params">&#123;author, postTime&#125;</span>) =&gt;</span> (</span><br><span class="line">    &lt;footer&gt;</span><br><span class="line">        &lt;span&gt;&#123;author&#125;&lt;<span class="regexp">/span&gt;@&lt;time&gt;&#123;postTime&#125;&lt;/</span>time&gt;</span><br><span class="line">    &lt;/footer&gt;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> Item = <span class="function"><span class="params">item</span> =&gt;</span> (</span><br><span class="line">    &lt;div&gt;</span><br><span class="line">        &lt;Header &#123;...item&#125; /&gt;</span><br><span class="line">        &lt;Content &#123;...item&#125; /&gt;</span><br><span class="line">        &lt;Footer &#123;...item&#125; /&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> List = <span class="function">(<span class="params">&#123;items&#125;</span>) =&gt;</span> (</span><br><span class="line">    &lt;ul&gt;</span><br><span class="line">        &#123;items.map(Item)&#125;</span><br><span class="line">    &lt;/ul&gt;</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
</li>
</ul>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
      </div>
      
      
      
    </div>

    
    


</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">郭泽</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js" integrity="sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script>

  
<script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.0/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.2.8/pdfobject.min.js","integrity":"sha256-tu9j5pBilBQrWSDePOOajCUdz6hWsid/lBNzK4KgEPM="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js"></script>

  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":{"light":"default","dark":"dark"},"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mermaid/9.1.3/mermaid.min.js","integrity":"sha256-TIYL00Rhw/8WaoUhYTLX9SKIEFdXxg+yMWSLVUbhiLg="}}</script>
  <script src="/js/third-party/tags/mermaid.js"></script>

  <script src="/js/third-party/fancybox.js"></script>


  





</body>
</html>
